package com.teradata.repository;

import com.teradata.entity.User;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Repository
public class UserRespository {
    private Map<Long, User> repository = new ConcurrentHashMap<Long, User>();

    public boolean saveUser(User user) {
        return repository.put(Long.parseLong(user.getId()), user) == null;
    }

    public Collection<User> findAll() {
        return repository.values();
    }

    public Flux<User> allUsers() {
        return Flux.fromIterable(findAll());
    }

}
